package com.iwunu.gateway.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.iwunu.gateway.entity.FaceLock;

import io.lettuce.core.dynamic.annotation.Param;

/**
 * @author kinfeng
 * @date 2021/3/18 10:00 AM
 * @desc
 */
@Repository
public interface FaceLockRepository extends JpaRepository<FaceLock, Long> , JpaSpecificationExecutor<FaceLock> {
		
	   @Query(value="select i from FaceLock i where i.id=:lockId ")
	   FaceLock selectFaceLockById(@Param("lockId") Long lockId);
	    
	    @Query(value="select i from FaceLock i where i.clientId=:clientId and i.isDel= false ")
	    FaceLock selectFaceLockByMac(@Param("clientId") String clientId);
		
	    @Query(value="select i from FaceLock i where i.clientId=:clientId and i.isDel= false ")
	    FaceLock selectFaceLockByBussinessId(@Param("clientId") String clientId);
	    
	    @Transactional
		@Modifying 
	    @Query(value="update FaceLock i set i.isDel=true where  i.id=:lockId ")
	     int delByLockId(@Param("lockId") Long lockId);
	    
		 @Transactional
		 @Modifying 
		 @Query(value="update t_lock  set ownerId =?2,bussinessId=?3 where  id in (?1) and isDel= false " ,nativeQuery = true)
		  int changeMember(@Param("lockIds")List<Integer> lockIds,@Param("userId") Integer userId,@Param("userNo") String userNo);
		 
		 @Transactional
		 @Modifying 
		 @Query(value="update t_lock  set ownerId =?2,bussinessId=?3,isNewLock = true, pushType=1 where  id in (?1) and isDel= false " ,nativeQuery = true)
		  int changePushMember(@Param("lockIds")List<Integer> lockIds,@Param("userId") Integer userId,@Param("userNo") String userNo);
		 
		 @Transactional
		 @Modifying 
		 @Query(value="update t_lock  set ownerId =?2 where  id in (?1) and isDel= false " ,nativeQuery = true)
		  int changeMember(@Param("lockIds")List<Integer> lockIds,@Param("userId") Integer userId);
}


